﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:System="clr-namespace:System;assembly=mscorlib"
                    xmlns:local="clr-namespace:ESRI.ArcGIS.Client.Toolkit"
                    xmlns:client="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client"
                    xmlns:toolkit="clr-namespace:ESRI.ArcGIS.Client.Toolkit.Primitives">

    <Style TargetType="{x:Type local:EditorWidget}">
        <Setter Property="Background">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFFDFDFD" Offset="0" />
                    <GradientStop Color="#FFEFF1F3" Offset="0.5" />
                    <GradientStop Color="#FFCCD3D8" Offset="1" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:EditorWidget}">
                    <StackPanel Margin="0,0,0,0">
                        <StackPanel.Resources>

                            <Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
                                <Setter Property="Margin" Value="2" />
                                <Setter Property="HorizontalAlignment" Value="Stretch" />
                                <Setter Property="VerticalAlignment" Value="Stretch" />
                                <Setter Property="HorizontalContentAlignment" Value="Center" />
                                <Setter Property="VerticalContentAlignment" Value="Center" />
                                <Setter Property="Background" Value="Transparent" />
                                <Setter Property="Padding" Value="0" />
                                <Setter Property="IsEnabled" Value="{Binding Path=Command.CanExecute}" />
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type Button}">
                                            <Grid x:Name="handScale" Cursor="Hand" Margin="2,0,2,0"
                                                  HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                                  VerticalAlignment="{TemplateBinding VerticalAlignment}"
                                                  RenderTransformOrigin="0.5,0.5">
                                                <Grid.RenderTransform>
                                                    <ScaleTransform/>
                                                </Grid.RenderTransform>
                                                <VisualStateManager.VisualStateGroups>
                                                    <VisualStateGroup x:Name="CommonStates">
                                                        <VisualState x:Name="Normal">
                                                            <Storyboard>
                                                                <DoubleAnimation To="0" FillBehavior="HoldEnd" Storyboard.TargetName="backGlow" 
                                                                                 Storyboard.TargetProperty="Opacity" Duration="0:0:0.4" />
                                                                <DoubleAnimation To="1" Storyboard.TargetName="handScale" BeginTime="0:0:0" 
                                                                                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" Duration="0:0:0.1" />
                                                                <DoubleAnimation To="1" Storyboard.TargetName="handScale" BeginTime="0:0:0" 
                                                                                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" Duration="0:0:0.1" />
                                                            </Storyboard>
                                                        </VisualState>
                                                        <VisualState x:Name="MouseOver">
                                                            <Storyboard>
                                                                <DoubleAnimation To="0.75" FillBehavior="HoldEnd" Storyboard.TargetName="backGlow" 
                                                                                 Storyboard.TargetProperty="Opacity" Duration="0:0:0.1" />
                                                                <DoubleAnimation To="1.5" Storyboard.TargetName="handScale" BeginTime="0:0:0" 
                                                                                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" Duration="0:0:0.1" />
                                                                <DoubleAnimation To="1.5" Storyboard.TargetName="handScale" BeginTime="0:0:0" 
                                                                                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" Duration="0:0:0.1" />
                                                            </Storyboard>
                                                        </VisualState>
                                                        <VisualState x:Name="Disabled">
                                                            <Storyboard>
                                                                <DoubleAnimation To="0" FillBehavior="HoldEnd" 
                                                                                 Storyboard.TargetName="backGlow" Storyboard.TargetProperty="Opacity" Duration="0:0:0.4" />
                                                                <DoubleAnimation To="0.7" Storyboard.TargetName="handScale" BeginTime="0:0:0" 
                                                                                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" Duration="0:0:0.1" />
                                                                <DoubleAnimation To="0.7" Storyboard.TargetName="handScale" BeginTime="0:0:0" 
                                                                                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" Duration="0:0:0.1" />
                                                                <DoubleAnimation Duration="0:0:0.4" FillBehavior="HoldEnd" Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Opacity" To="0.5" />
                                                            </Storyboard>
                                                        </VisualState>
                                                    </VisualStateGroup>
                                                </VisualStateManager.VisualStateGroups>
                                                    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
                                                        <Rectangle x:Name="backGlow" IsHitTestVisible="False" Margin="-10">
                                                            <Rectangle.Fill>
                                                                <RadialGradientBrush  Center="0.5, 0.5" RadiusY="0.5">
                                                                    <GradientStop Color="#AAFFFFFF" Offset="0" />
                                                                    <GradientStop Color="#00FFFFFF" Offset="0.98" />
                                                                </RadialGradientBrush>
                                                            </Rectangle.Fill>
                                                        </Rectangle>
                                                        <ContentPresenter x:Name="contentPresenter"
                                                                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                                      Margin="{TemplateBinding Padding}"
                                                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                                      Content="{TemplateBinding Content}"
                                                                      ContentTemplate="{TemplateBinding ContentTemplate}" />
                                                    </Grid>
                                                </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>

                            <Style x:Key="BorderStyle" TargetType="{x:Type Border}">
                                <Setter Property="Margin" Value="5,0,0,0" />
                                <Setter Property="Padding" Value="3" />
                                <Setter Property="CornerRadius" Value="5" />
                                <Setter Property="BorderThickness" Value="1" />
                            </Style>

                            <Style x:Key="ToggleButtonStyle" TargetType="{x:Type ToggleButton}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ToggleButton}">
                                            <Grid x:Name="handScale" Cursor="Hand" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5" Background="Transparent">
                                                <Grid.RenderTransform>
                                                    <ScaleTransform/>
                                                </Grid.RenderTransform>
                                                <VisualStateManager.VisualStateGroups>
                                                    <VisualStateGroup x:Name="CommonStates">
                                                        <VisualState x:Name="Normal">
                                                            <Storyboard>
                                                                <DoubleAnimation Duration="0:0:0.4" FillBehavior="HoldEnd"
                                                                                 Storyboard.TargetName="backGlow"
                                                                                 Storyboard.TargetProperty="Opacity" To="0" />
                                                                <DoubleAnimation BeginTime="0:0:0" Duration="0:0:0.1"
                                                                                 Storyboard.TargetName="handScale"
                                                                                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" To="1" />
                                                                <DoubleAnimation BeginTime="0:0:0" Duration="0:0:0.1"
                                                                                 Storyboard.TargetName="handScale" 
                                                                                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" To="1" />
                                                            </Storyboard>
                                                        </VisualState>
                                                        <VisualState x:Name="MouseOver">
                                                            <Storyboard>
                                                                <DoubleAnimation Duration="0:0:0.1" FillBehavior="HoldEnd"
                                                                                 Storyboard.TargetName="backGlow"
                                                                                 Storyboard.TargetProperty="Opacity" To="0.75" />
                                                                <DoubleAnimation BeginTime="0:0:0" Duration="0:0:0.1"
                                                                                 Storyboard.TargetName="handScale"
                                                                                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" To="1.5" />
                                                                <DoubleAnimation BeginTime="0:0:0" Duration="0:0:0.1"
                                                                                 Storyboard.TargetName="handScale"
                                                                                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" To="1.5" />
                                                            </Storyboard>
                                                        </VisualState>
                                                        <VisualState x:Name="Disabled">
                                                            <Storyboard>
                                                                <DoubleAnimation Duration="0:0:0.4" FillBehavior="HoldEnd"
                                                                                 Storyboard.TargetName="backGlow"
                                                                                 Storyboard.TargetProperty="Opacity" To="0" />
                                                                <DoubleAnimation BeginTime="0:0:0" Duration="0:0:0.1"
                                                                                 Storyboard.TargetName="handScale"
                                                                                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" To="0.7" />
                                                                <DoubleAnimation BeginTime="0:0:0" Duration="0:0:0.1"
                                                                                 Storyboard.TargetName="handScale"
                                                                                 Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" To="0.7" />
                                                            </Storyboard>
                                                        </VisualState>
                                                    </VisualStateGroup>
                                                    <VisualStateGroup x:Name="CheckStates">
                                                        <VisualState x:Name="Checked" />
                                                        <VisualState x:Name="Unchecked" />
                                                    </VisualStateGroup>
                                                    <VisualStateGroup x:Name="FocusStates">
                                                        <VisualState x:Name="Focused" />
                                                        <VisualState x:Name="Unfocused" />
                                                    </VisualStateGroup>
                                                </VisualStateManager.VisualStateGroups>
                                                    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
                                                        <Rectangle x:Name="backGlow" IsHitTestVisible="False" Margin="-10">
                                                            <Rectangle.Fill>
                                                                <RadialGradientBrush  Center="0.5, 0.5" RadiusY="0.5">
                                                                    <GradientStop Color="#AAFFFFFF" Offset="0" />
                                                                    <GradientStop Color="#00FFFFFF" Offset="0.98" />
                                                                </RadialGradientBrush>
                                                            </Rectangle.Fill>
                                                        </Rectangle>
                                                        <ContentPresenter x:Name="contentPresenter"
                                                                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                                      Margin="{TemplateBinding Padding}"
                                                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                                      Content="{TemplateBinding Content}"
                                                                      ContentTemplate="{TemplateBinding ContentTemplate}" />
                                                        <Rectangle x:Name="DisabledVisualElement" Fill="#AAFFFFFF" RadiusX="3" 
                                                               RadiusY="3" IsHitTestVisible="false" Opacity="0" />
                                                        <Rectangle x:Name="FocusVisualElement" Stroke="#FF6DBDD1" StrokeThickness="1" 
                                                               RadiusX="2" RadiusY="2" Margin="1" IsHitTestVisible="false" Opacity="0" />
                                                    </Grid>
                                                </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </StackPanel.Resources>
                        <local:TemplatePicker Map="{TemplateBinding Map}" 
                                              GeometryServiceCredentials="{TemplateBinding GeometryServiceCredentials}"
                                                  GeometryServiceUrl="{TemplateBinding GeometryServiceUrl}"
											  GeometryServiceToken="{TemplateBinding GeometryServiceToken}"
											      ProxyUrl="{TemplateBinding ProxyUrl}"
                                                  ShowAttributesOnAdd="{TemplateBinding ShowAttributesOnAdd}"
                                                  LayerIDs="{TemplateBinding LayerIDs}"
                                                  AlwaysDisplayDefaultTemplates="{TemplateBinding AlwaysDisplayDefaultTemplates}"
                                                  Continuous="{TemplateBinding Continuous}"
                                                  AutoSelect="{TemplateBinding AutoSelect}"
                                                  Freehand="{Binding Freehand}"
                                                  AutoComplete="{Binding AutoComplete}"
                                                  BorderBrush="{TemplateBinding BorderBrush}"
                                                  Background="{TemplateBinding Background}"
                                                  SnapDistanceSymbol="{TemplateBinding SnapDistanceSymbol}"
                                                  VertexSymbol="{TemplateBinding VertexSymbol}"
                                                  DrawLineSymbol="{TemplateBinding DrawLineSymbol}"
                                                  DrawFillSymbol="{TemplateBinding DrawFillSymbol}"
                                                  x:Name="TemplatePicker">
                            <local:TemplatePicker.Template>
                                <ControlTemplate TargetType="local:TemplatePicker">
                                    <Border Style="{StaticResource BorderStyle}" HorizontalAlignment="Center"                                            
                                        BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}">
                                        <toolkit:TemplatePanel Templates="{TemplateBinding Templates}" StackCount="2" StackDirection="Horizontal"
                                              ItemTemplate="{TemplateBinding ItemTemplate}" />
                                    </Border>
                                </ControlTemplate>
                            </local:TemplatePicker.Template>
                        </local:TemplatePicker>
                        <Border x:Name="ToolsContainer" HorizontalAlignment="Center" Style="{StaticResource BorderStyle}" 
                                VerticalAlignment="Top" Background="{TemplateBinding Background}" 
                                BorderBrush="{TemplateBinding BorderBrush}" Height="40">
                            <StackPanel Orientation="Horizontal">
                                <Button x:Name="NewSelect"  Command="{Binding Select}" CommandParameter="New" 
                                        ToolTipService.ToolTip="New selection" Style="{StaticResource ButtonStyle}">
                                    <Image  Stretch="None" Source="/ESRI.ArcGIS.Client.Toolkit;component/Images/NewSelection.png"/>                                                                            
                                </Button>
                                <Button x:Name="AddSelect" Command="{Binding Select}" CommandParameter="Add" 
                                        ToolTipService.ToolTip="Add to selection" Style="{StaticResource ButtonStyle}">
                                    <Image  Stretch="None" Source="/ESRI.ArcGIS.Client.Toolkit;component/Images/AddToSelection.png"/>
                                </Button>
                                <Button  x:Name="RemoveSelect" Command="{Binding Select}" CommandParameter="Remove" 
                                         ToolTipService.ToolTip="Remove from selection" Style="{StaticResource ButtonStyle}">
                                    <Image Stretch="None" Source="/ESRI.ArcGIS.Client.Toolkit;component/Images/RemoveFromSelection.png"/>
                                </Button>
                                <Button Command="{Binding ClearSelection}" x:Name="ClearSelect" 
                                                     Style="{StaticResource ButtonStyle}" ToolTipService.ToolTip="Clear selection">
                                    <Image Source="/ESRI.ArcGIS.Client.Toolkit;component/Images/Clear.png" Stretch="None" />
                                </Button>
                                <Button Command="{Binding DeleteSelected}" x:Name="DeleteSelect" 
                                                     Style="{StaticResource ButtonStyle}" ToolTipService.ToolTip="Delete selected features">
                                    <Image Source="/ESRI.ArcGIS.Client.Toolkit;component/Images/deleteFeature.png" Stretch="None" />
                                </Button>
                                <Button x:Name="EditGeometry" Command="{Binding EditVertices}" ToolTipService.ToolTip="Edit Geometry" 
                                        Style="{StaticResource ButtonStyle}">
                                    <Image  Stretch="None" Source="/ESRI.ArcGIS.Client.Toolkit;component/Images/showVertices.png"/>
                                </Button>
                                <Button x:Name="Reshape" Command="{Binding Reshape}" ToolTipService.ToolTip="Reshape" 
                                        Style="{StaticResource ButtonStyle}">
                                    <Image Stretch="None" Source="/ESRI.ArcGIS.Client.Toolkit;component/Images/reshape.png"/>
                                </Button>
                                <Button Command="{Binding Union}" x:Name="Union" 
                                                     Style="{StaticResource ButtonStyle}" ToolTipService.ToolTip="Union features">
                                    <Image Source="/ESRI.ArcGIS.Client.Toolkit;component/Images/union.png" Stretch="None" />
                                </Button>
                                <Button Command="{Binding Cut}" x:Name="Cut" 
                                                     Style="{StaticResource ButtonStyle}" ToolTipService.ToolTip="Cut features">
                                    <Image Source="/ESRI.ArcGIS.Client.Toolkit;component/Images/cut.png" Stretch="None" />
                                </Button>
                                <Button Command="{Binding Save}" x:Name="Save" 
                                                     Style="{StaticResource ButtonStyle}" ToolTipService.ToolTip="Save edits">
                                    <Image Source="/ESRI.ArcGIS.Client.Toolkit;component/Images/commit.png" Stretch="None" />
                                </Button>
                                <Button x:Name="DisplayAttribute" Style="{StaticResource ButtonStyle}" IsEnabled="True"
                                        ToolTipService.ToolTip="Display attributes">
                                    <Image Source="/ESRI.ArcGIS.Client.Toolkit;component/Images/attributes.png" Stretch="None" />
                                </Button>
                                <Grid Margin="5,0,0,0">
                                    <ToggleButton x:Name="Options" Content="..." Style="{StaticResource ToggleButtonStyle}" />
                                    <Popup AllowsTransparency="True" IsOpen="{Binding IsChecked, ElementName=Options}"
                                           Visibility="{Binding ElementName=Options, Path=Visibility}" Placement="Bottom"
                                           PlacementTarget="{Binding ElementName=Options}" HorizontalOffset="-100" StaysOpen="False">
                                        <Border x:Name="PopupBorder" Style="{StaticResource BorderStyle}" 
                                                BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}">
                                            <StackPanel>
                                                <TextBlock><Run>Add options</Run></TextBlock>
                                                <StackPanel Margin="10,5">
                                                    <CheckBox IsChecked="{Binding Path=Freehand, Mode=TwoWay}" Content="Freehand draw"
                                                              ToolTipService.ToolTip="for polylines and polygons" />
                                                    <CheckBox IsChecked="{Binding Path=AutoComplete, Mode=TwoWay}" Content="Autocomplete"
                                                              ToolTipService.ToolTip="for polygons" />
                                                </StackPanel>
                                            </StackPanel>
                                        </Border>
                                    </Popup>
                                </Grid>
                            </StackPanel>
                        </Border>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
